#
# @lc app=leetcode.cn id=58 lang=python3
#
# [58] 最后一个单词的长度
#

# @lc code=start
class Solution:
    def lengthOfLastWord(self, s: str) -> int:
        s = s.rstrip()
        if not s: return 0
        i = len(s) - 1
        while i >= 0:
            if s[i] == ' ':
                return len(s) - i - 1
            i -= 1
        return len(s)
# @lc code=end

